// pages/result/index.js
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isPass:"本次考试不及格，请再接再厉！",
    tishi:"有志者事竟成，破釜沉舟，百二秦川终属楚！",
    percent: 0,
    info: {},
  },
  //返回首页
  toIndex: function () {
    wx.reLaunch({
        url: "/pages/tiku/fenlei"
    });
},
onShareAppMessage: function () {
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    try {
      var token = wx.getStorageSync('token')
      if (token) {
        try {
          var empinfo = wx.getStorageSync('empinfo')
          if (empinfo) {
              var id = options.id;
              app.formPost('/wx/test/get-transcript-result',{
                transcriptId: id,
                employeeId: empinfo.employeeId,
              }).then(res=>{
                //wx.stopPullDownRefresh()
                  if(res.code == 200){
                    //console.log(res.transcriptInfo)
                    that.setData({
                      info: res.transcriptInfo,
                      percent: (res.transcriptInfo.correctlyNum / res.transcriptInfo.totalNum * 100).toFixed(1)
                    })
                    if(res.transcriptInfo.excamMark >= res.transcriptInfo.passScore){
                      that.setData({
                          isPass:"恭喜你，本次考试及格！",
                          tishi:"苦心人天不负，卧薪尝胆，三千越甲可吞吴！"
                      })
                  } 
                }
              }).catch(e => {
                wx.showModal({
                  title: e
                })
              })
          }else{
            wx.reLaunch({
              url: '/pages/user/bind/index',
            });
          }
        } catch (e) {
          wx.reLaunch({
            url: '/pages/user/bind/index',
          });
        }
      }else{
        wx.reLaunch({
          url: '/pages/user/bind/index',
        });
      }
    } catch (e) {
      wx.reLaunch({
        url: '/pages/user/bind/index',
      });
    }
  },
  toAgainTest: function (){
    //跳转到任务界面
    wx.switchTab({
      url: '/pages/tiku/fenlei',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})